package logic

import (
	"2301_dockers/model"
	"context"
	"gorm.io/gorm"

	"2301_dockers/dockersrpc/dockersrpc"
	"2301_dockers/dockersrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type DockerUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDockerUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DockerUpdateLogic {
	return &DockerUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DockerUpdateLogic) DockerUpdate(in *dockersrpc.DockerUpdateRequest) (*dockersrpc.DockerUpdateResponse, error) {
	// todo: add your logic here and delete this line

	var docker = model.Docker{
		Model:            gorm.Model{ID: uint(in.Id)},
		Name:             in.Name,
		AffiliatedCampus: in.AffiliatedCampus,
		Department:       in.Department,
		Price:            float64(in.Price),
		Professionals:    in.Professionals,
		Label:            in.Label,
		Diagnosis:        float64(in.Diagnosis),
		Desc:             in.Desc,
		Img:              in.Img,
	}
	model.DB.Debug().Where("id=?", docker.ID).Updates(&docker)

	return &dockersrpc.DockerUpdateResponse{
		Id: int64(docker.ID),
	}, nil
}
